a = input()
f = 0
if len(a)==4:
    n1 = a[0]
    n2 = a[1]
    n3 = a[2]
    n4 = a[3]
    spis=[int(n1),int(n2),int(n3),int(n4), int(n1+n2), int(n1+n2 + n3), int(n2 + n3),int(n1 +n2 +n3 + n4),int(n3 + n4), int(n2 + n3 + n4)]
    spis.sort()
    spis = spis[::-1]
    for x in spis:
        f = 1
        for d in range(2, x //2 + 1):
            if x % d == 0:
                f = 0
                break  
        if f == 1:
            print(x)
            break
    if f == 0:
        print(0)
else:
    print(0)
